package com.konglz.iblog.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Description
 * @Author konglz
 * @Data 2023/2/22 16:33
 */

@EnableKnife4j
@EnableSwagger2
@Configuration
public class Knife4jConfig {


    private Boolean enable;

    private Boolean profilesEnable(Environment environment){
        //根据profiles的active选择不同的swagger配置
        Profiles profiles = Profiles.of("dev","pub");
        enable = environment.acceptsProfiles(profiles);
        return enable;
    }


    //前端api
    @Bean(value = "createApi")
    public Docket createApi(Environment environment) {
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("iblog接口")
                        .description("iblog接口稳定")
                        .termsOfServiceUrl("http://www.xx.com/")
                        .contact(new Contact("konglz","","1822521315@qq.com"))
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("前端接口api")
                .enable(true)
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.konglz.iblog.controller.api"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    //后端api
    @Bean(value = "createApi2")
    public Docket createApi2(Environment environment) {
        Docket docket=new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("iblog接口")
                        .description("iblog接口")
                        .termsOfServiceUrl("http://www.xx.com/")
                        .contact(new Contact("konglz","","1822521315@qq.com"))
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("后端接口api")
                .enable(true)
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("com.konglz.iblog.controller.system"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
}
